/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 87111
 * Date: 2025-10-31
 * Time: 19:35
 */
public class Demo3 {
    public static void main(String[] args) {
        Object locker = new Object();
        Thread t1 = new Thread(() -> {
            try {
                System.out.println("t1线程结束前");
                synchronized(locker) {
                    locker.wait();
                }
                System.out.println("t1线程结束后");
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
        });
        Thread t2 = new Thread(() -> {
            try {
                System.out.println("t2线程结束前");
                synchronized(locker) {
                    locker.wait();
                }
                System.out.println("t2线程结束后");
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
        });
        Thread t3 = new Thread(() -> {
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
            synchronized(locker) {
                locker.notifyAll();
            }
        });
        t1.start();
        t2.start();
        t3.start();
    }
}
